package com.clqteam.serviceimpl;

import java.util.List;

import com.clqteam.dao.OrderDao;
import com.clqteam.daoimpl.OrderDaoImpl;
import com.clqteam.model.Order;
import com.clqteam.service.OrderService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 
 * @author ZHX
 *
 */
public class OrderServiceImpl implements OrderService{

	OrderDao oDao = new OrderDaoImpl();
	
	
	@Override
	public JSONObject findAllOrder(int page, int rows) {
		JSONObject j = new JSONObject();
		List<Order> orders = oDao.getAllOrder(page,rows);
		int total = oDao.getAllCountOrder();
		j.put("total", total);
		JSONArray js = new JSONArray();
		for (Order order : orders) {
			JSONObject oj = new JSONObject();
			oj.put("eId", order.geteId());
			oj.put("eName", order.geteName());
			oj.put("oClass", order.getoClass());
			oj.put("oClassId", order.getoClassId());
			oj.put("oId", order.getoId());
			oj.put("oMeney", order.getoMoney());
			oj.put("vId", order.getvId());
			oj.put("oTime", order.getoTime());
			js.add(oj);
		}
		j.put("rows", js);
		return j;
	}
	
	@Override
	public JSONObject findOrderByClass(int oClassId,int page,int rows) {
		JSONObject j = new JSONObject();
		List<Order> orders = oDao.getOrderByClass(oClassId,page,rows);
		int total = oDao.getCountOrderByClass(oClassId);
		j.put("total", total);
		JSONArray js = new JSONArray();
		for (Order order : orders) {
			JSONObject oj = new JSONObject();
			oj.put("eId", order.geteId());
			oj.put("eName", order.geteName());
			oj.put("oClass", order.getoClass());
			oj.put("oClassId", order.getoClassId());
			oj.put("oId", order.getoId());
			oj.put("oMeney", order.getoMoney());
			oj.put("vId", order.getvId());
			oj.put("oTime", order.getoTime());
			js.add(oj);
		}
		j.put("rows", js);
		return j;
	}

	@Override
	public int deleteOrderByOId(int oId) {
	
		return oDao.deleteOrderByOId(oId);
	}

	@Override
	public JSONObject findInfoByKey(String key,int page,int rows) {
		JSONObject j = 	new JSONObject();
		int total = oDao.getCountInfoByKey(key);
		j.put("total", total);
		List<Order> orders = oDao.getInfoByKey(key, page, rows);
		JSONArray js = new JSONArray();
		for (Order order : orders) {
			JSONObject oj = new JSONObject();
			oj.put("eId", order.geteId());
			oj.put("eName", order.geteName());
			oj.put("oClass", order.getoClass());
			oj.put("oClassId", order.getoClassId());
			oj.put("oId", order.getoId());
			oj.put("oMeney", order.getoMoney());
			oj.put("vId", order.getvId());
			oj.put("oTime", order.getoTime());
			js.add(oj);
		}
		j.put("rows", js);
		return j;
	}

	
	

}
